/*
 * Copyright (c) 2020 Carnegie Lee
 * All rights reserved
 */
package com.geekc.zkdistributelock.lock.impl;

import com.geekc.zkdistributelock.lock.DistributeLock;

/**
 * 分布式锁抽象类
 * @author Carnegie Lee
 */
public abstract class AbstractDistributeLock implements DistributeLock {

    @Override
    public final void lock() {
        if (tryLock()) {
            System.out.println("获取锁成功");
        } else {
            System.out.println("获取锁失败");
        }
    }

    @Override
    public final void unlock() {
        if (tryRelease()) {
            System.out.println("释放锁成功");
        } else {
            System.out.println("释放锁失败");
        }
    }

    protected abstract boolean tryLock();

    protected abstract boolean tryRelease();
}
